package com.hellodoctor.util;

import java.util.ArrayList;
import java.util.List;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.Role;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;

public class MyUtil {
	public static String getSpeciality(int specialityId) {
		String[] specialities = LConstants.specialities;
		System.out.println("Speciality>>>"+specialityId);
		
		return specialities[specialityId - 1];
	}

	public static String getQualification(int qualificationId) {
		String[] qualifications = LConstants.qualifications;
		return qualifications[qualificationId - 1];
	}
	
	public static boolean isDoctor(long userId){
		User usr = null;
		boolean flag= false;
		List<Role> roles = new ArrayList<Role>();
		try {
			usr = UserLocalServiceUtil.fetchUser(userId);
			 roles = usr.getRoles();
		} catch (SystemException e) {
			e.printStackTrace();
		}
		for(Role role : roles){
			
			String roleName = role.getName();
			
			if(roleName.equalsIgnoreCase("Doctor")||roleName.equalsIgnoreCase("Administrator")){
				flag = true;
				break;
			}
		}
		return flag;
	}
	public static boolean isPatient(long userId){
		User usr = null;
		boolean flag= false;
		List<Role> roles = new ArrayList<Role>();
		try {
			usr = UserLocalServiceUtil.fetchUser(userId);
			 roles = usr.getRoles();
		} catch (SystemException e) {
			e.printStackTrace();
		}
		for(Role role : roles){
			String roleName = role.getName();
			if(roleName.equalsIgnoreCase("Patient")||roleName.equalsIgnoreCase("Administrator")){
				flag = true;
				break;
			}
		}
		return flag;
	}
}
